// 将自定义的的config 转换为Ext可识别的config
Ext.require('AM.util.URL');


Ext.define('AM.data.InitConfig', {


    singleton:true,


    page:function (o, xbxConfig) {
        var style = o.el.dom.style;
        AM.data.InitConfig._setStyles(style, xbxConfig, ['background-image', 'background-color'])

        var cutOverAudioName = xbxConfig['cut-over-audio-name'];
        var animName = xbxConfig['anim-name'];
        if (!Ext.isEmpty(cutOverAudioName)) {
            o.cutOverAudioName = cutOverAudioName;
        }
        if (!Ext.isEmpty(animName)) {
            o.animName = animName;
        }
    },


    text:function (o, xbxConfig) {
        var style = o.el.dom.style;
        var styles = ['left', 'top', 'width', 'height', 'background-image', 'background-color', 'opacity'];
        AM.data.InitConfig._setStyles(style, xbxConfig, styles);

        style['-webkit-transform'] = xbxConfig['transform']
        var innerHTML = xbxConfig['inner-html'];
        if (!Ext.isEmpty(innerHTML))
            o.el.dom.innerHTML = innerHTML;
    },


    image:function (o, xbxConfig) {
        var style = o.el.dom.style;
        var styles = ['left', 'top', 'width', 'height',  'opacity'];
        AM.data.InitConfig._setStyles(style, xbxConfig, styles);

        style['-webkit-transform'] = xbxConfig['transform']

        var imageName = xbxConfig['image-name'];
        o.imageName = imageName;
        style['background-image'] = 'url(' + AM.util.URL.image + imageName + ')';

    },


    audio: function(o, xbxConfig){
        var style = o.el.dom.style;
        var styles = ['left', 'top', 'width', 'height'];
        AM.data.InitConfig._setStyles(style, xbxConfig, styles);

        style['-webkit-transform'] = xbxConfig['transform']
        var audioName = xbxConfig['audio-name'];
        o.audioName = audioName;
        var src = AM.util.URL.audio + audioName;;
        o.el.dom.src = src;
    },


    _setStyle: function(style, config, key) {
        if (Ext.isEmpty(config[key]))
            return;
        style[key] = config[key];
    },


    _setStyles: function(style, config, arr) {
        Ext.each(arr, function(key) {
            AM.data.InitConfig._setStyle(style, config, key);
        })
    }


})